package com.heima.kafka.simple;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;

import java.util.Properties;

public class ProducerFastStart {
    private static final String TOPIC = "itcast-heima";
    public static void main(String[] args) {
        //封装kafka的配置信息
        Properties properties = new Properties();
        //配置broker信息
        //kafka服务端地址
        properties.put("bootstrap.servers","192.168.200.130:9092");
        //key和value的系列化方式
        properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,"org.apache.kafka.common.serialization.StringSerializer");
        properties.put(ProducerConfig.RETRIES_CONFIG,10);
        //生产者对象
        KafkaProducer<String,String> producer = new KafkaProducer<String, String>(properties);

        ProducerRecord<String, String> record = new ProducerRecord<>(TOPIC, "hello kafka");

        producer.send(record); //发送消息

        producer.close();









    }
}
